package learning.lesson.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import learning.lesson.bean.Product;
import learning.lesson.dao.ProductDAO;

public class UpdateProductServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	ProductDAO dao = new ProductDAO();
    Product  p=new Product();
	/**
	 * 
	 */

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		request.setCharacterEncoding("gbk");
		response.setCharacterEncoding("gbk");
		p.setId(request.getParameter("id"));
		p.setName(request.getParameter("name"));
		p.setPrice(Double.parseDouble(request.getParameter("price")));
		p.setStock(Integer.parseInt(request.getParameter("stock")));
		dao.UpdateProduct(p);
		RequestDispatcher dispatcher = request
				.getRequestDispatcher("product/all.jsp");
		request.setAttribute("list", dao.queryAll());
		dispatcher.forward(request, response);
	}

}
